//
//  CTDocAudioCell.m
//  IfengNews
//
//  Created by lihongdan on 14-7-9.
//
//

#import "CTDocAudioCell.h"
#import "BlockUI.h"
#import "UIView+Utils.h"
#import "CLDocViewController.h"


@implementation CTDocAudioCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        self.bgView=[[UIView alloc] init];
        self.bgView.frame=CGRectMake(0, 0, GlobleWidth, 64.f);
        self.bgView.backgroundColor=self.backgroundColor;
        [self addSubview:self.bgView];
        
        self.audioView=[[IFAudioView alloc] init];
       // self.audioView.leftLabel.text=@"音频版";
        self.frame=CGRectMake(0, 0, GlobleWidth, 64.f);
        [self.bgView addSubview:self.audioView];
    
        self.backgroundColor=self.contentView.backgroundColor=self.backgroundColor;
       
        UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
        button.frame=CGRectMake(self.audioView.slider.right, 10.f, 40.f, 36.f);
        [self.bgView addSubview:button];
        __weak typeof (self) me=self;
        [button handleControlEvent:UIControlEventTouchUpInside withBlock:^(id sender) {
            
            NSString *tag=[NSString stringWithFormat:@"%d",[me.ctrl hash]];
            
            if(![tag isEqualToString:[IFAudioPlayerManager shareInstance].tag]){
                [[IFAudioPlayerManager shareInstance] stop];
                
//                if(![me __isReachNet]){
//                    [me showTieAlertMessage:@"无法连接" subMessage:@"请检查网络"];
//                    return ;
//                }
                
            }
            
            [IFAudioPlayerManager shareInstance].tag=tag;
            me.ctrl.isRunAudio=YES;
            [me.audioView clickPlay];
        }];
        
        [self.bgView addSubview:self.audioView.slider];
    }
    return self;
}

- (void)checkStatus{
    [self.audioView checkStatus];
}

- (void)setUrl:(NSString *)url{
    _url=url;
    self.audioView.audioUrl=url;
}

@end
